<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class SmsController extends Controller
{
    public function sm(Request $request ,  $mobile) {
    // 注意,把阿里短信SDK放在/vender下
    require (base_path(). '/vendor/alisms/TopSdk.php');
    $appkey = '你的阿里大鱼appkey';
    $secret = '你的阿里大鱼secret密钥';
    $c = new \TopClient; // 前面的'/'代表根空间,不能少
    $c->appkey = $appkey;
    $c->secretKey = $secret;
    $rand = mt_rand(1000,9999); // 随机验证码
    // 把随机数存入session用于验证
    $request->session()->put('smscode' , $rand);
    //以下为阿里提供的模板及函数
    $req = new \AlibabaAliqinFcSmsNumSendRequest;
    $req->setExtend("123456");
    $req->setSmsType("normal");
    $req->setSmsFreeSignName("瓜子网");
    $req->setRecNum($mobile);
    $req->setSmsParam("{\"code\":\"{$rand}\",\"product\":\"瓜子贷\"}");
    $req->setSmsTemplateCode("SMS_4715200");
    print_r($req);
    echo $c->execute($req); // 输出结果,默认json格式

}
    //检测短信是否通过
    public function checksm(Request $request){
    
    return $request->session()->get('smscode');

    }

}
